"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const feifanc_1 = __importDefault(require("../util/feifanc"));
const config_1 = require("../config");
exports.default = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
    if (config_1.img.includes(path_1.default.extname(req.path))) {
        return next();
    }
    const pathName = path_1.default.join(__dirname, "./log.json");
    const token = req.signedCookies.feifan;
    const data = {
        method: req.method,
        reqUrl: req.path,
        user: token ? token.user : "游客",
        body: req.body,
        query: req.query,
        time: feifanc_1.default.date("all"),
    };
    next();
    yield fs_1.default.promises.appendFile(pathName, JSON.stringify(data) + ",");
});
